package com.translate.web.service.impl;

import com.translate.web.constant.RedisConstant;
import com.translate.web.dao.ServiceTypeMapper;
import com.translate.entity.ServiceType;
import com.translate.vo.contract.IServiceTypeVO;
import com.translate.web.service.IServiceTypeService;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class ServiceTypeServiceImpl extends BaseTranslateServiceImpl<ServiceType> implements IServiceTypeService {


	@Resource
	public void setRedisTemplate(RedisTemplate<String, ? extends Object> redisTemplate) {
		this.redisTemplate = redisTemplate;
	}

	public ServiceTypeServiceImpl(ServiceTypeMapper mapper) {
		super(mapper);
	}

	protected void insertPropteris(ServiceType data) {
		long time = System.currentTimeMillis() / 1000;
		data.setCreateTime(time);
		data.setUpdateTime(time);
	}

	protected void updatePropteris(ServiceType data) {
		data.setUpdateTime(System.currentTimeMillis() / 1000);
	}

	protected Class<ServiceType> getEntityClass() {
		return ServiceType.class;
	}

	/**
	 * 默认返回
	 *
	 * @param data
	 * @return
	 */
	protected int getId(ServiceType data) {
		return data.getId().intValue();
	}

	@Override
	public <VO extends IServiceTypeVO> List<VO> getListFromCache(Class<VO> target) {
		return this.entityConvertToVo(this.listToHash( RedisConstant.SERVER_TYPE, 100), target);
	}

	/**
	 * 获取服务类型信息
	 * @param serviceType
	 * @return
	 */
	@Override
	public ServiceType getServiceTypeMessage(ServiceType serviceType) {
		
		ServiceTypeMapper serviceTypeMapper = this.getBaseMapper();
		
		return serviceTypeMapper.selectByType(serviceType.getType());
	}
}
